package com.novellotus.iov.carvice.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.bean.RxDiagnosisChart;
import com.novellotus.iov.carvice.view.MyMarkerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Rich on 2017/10/11.
 */

public class ChartRecyclerAdapter extends RecyclerView.Adapter {

    List<RxDiagnosisChart> list;

    private boolean voltagetOpen = true, electricOpen = true, monomerVoltageOpen = true, resistanceOpen = true, batteryCaseOpen = true;
    private boolean voltagetFirst = true, electricFirst = true, monomerVoltageFirst = true, resistanceFirst = true, batteryCaseFirst = true;
    private final float CircleRadius = 3f;
    private Context context;
    private final float CircleHoleRadius = 1f;

    public ChartRecyclerAdapter(List<RxDiagnosisChart> list) {
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        this.context = parent.getContext();
        switch (viewType) {
            case 0:
                View viewVoltage = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_chart_voltage, parent, false);
                return new VoltageHolder(viewVoltage);
            case 1:
                View viewElectric = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_electric_chart, parent, false);
                return new ElectricHolder(viewElectric);
            case 2:
                View viewMonomerVoltage = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_monomer_voltage_chart, parent, false);
                return new MonomerVoltageHolder(viewMonomerVoltage);
            case 3:
                View viewResistance = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_resistance_chart, parent, false);
                return new ResistanceHolder(viewResistance);
            case 4:
                View viewBatteryCase = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_battery_case_chart, parent, false);
                return new BatteryCaseHolder(viewBatteryCase);

        }
        return null;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        switch (position) {
            case 0:
                initVoltage((VoltageHolder) holder);
                break;
            case 1:
                initElectric((ElectricHolder) holder);
                break;
            case 2:
                initMonomerVoltage((MonomerVoltageHolder) holder);
                break;
            case 3:
                initResistance((ResistanceHolder) holder);
                break;
            case 4:
                initBatteryCase((BatteryCaseHolder) holder);
                break;
        }

    }

    /**
     * @param holder 总电压
     */
    private void initVoltage(VoltageHolder holder) {
        if (voltagetFirst) {
            voltagetFirst = false;
            setChart(holder.lineChart);
            setTotalVoltageData(holder.lineChart);
        }

        if (voltagetOpen) {
            holder.lineChart.setVisibility(View.VISIBLE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow_down);
        } else {
            holder.lineChart.setVisibility(View.GONE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow);
        }
        holder.rlt_tittle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                voltagetOpen = !voltagetOpen;
                notifyDataSetChanged();
            }
        });
    }

    /**
     * @param holder 总电流
     */
    private void initElectric(ElectricHolder holder) {
        if (electricFirst) {
            electricFirst = false;
            setChart(holder.lineChart);
            setTotalCurrentData(holder.lineChart);
        }
        if (electricOpen) {
            holder.lineChart.setVisibility(View.VISIBLE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow_down);
        } else {
            holder.lineChart.setVisibility(View.GONE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow);
        }
        holder.rlt_tittle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                electricOpen = !electricOpen;
                notifyDataSetChanged();
            }
        });
    }

    /**
     * @param holder 单体电压
     */
    private void initMonomerVoltage(MonomerVoltageHolder holder) {
        if (monomerVoltageFirst) {
            monomerVoltageFirst = false;
            setChart(holder.lineChart);
            setMonomerVoltage(holder.lineChart);
        }
        if (monomerVoltageOpen) {
            holder.lineChart.setVisibility(View.VISIBLE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow_down);
        } else {
            holder.lineChart.setVisibility(View.GONE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow);
        }
        holder.rlt_tittle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                monomerVoltageOpen = !monomerVoltageOpen;
                notifyDataSetChanged();
            }
        });
    }

    /**
     * @param holder 绝缘电阻
     */
    private void initResistance(ResistanceHolder holder) {
        if (resistanceFirst) {
            resistanceFirst = false;
            setChart(holder.lineChart);
            setResistanceData(holder.lineChart);
        }
        if (resistanceOpen) {
            holder.lineChart.setVisibility(View.VISIBLE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow_down);
        } else {
            holder.lineChart.setVisibility(View.GONE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow);
        }
        holder.rlt_tittle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                resistanceOpen = !resistanceOpen;
                notifyDataSetChanged();
            }
        });
    }

    /**
     * @param holder 探针温度
     */
    private void initBatteryCase(BatteryCaseHolder holder) {
        if (batteryCaseFirst) {
            batteryCaseFirst = false;
            setChart(holder.lineChart);
            setBatteryCaseVoltage(holder.lineChart);
        }
        if (batteryCaseOpen) {
            holder.lineChart.setVisibility(View.VISIBLE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow_down);
        } else {
            holder.lineChart.setVisibility(View.GONE);
            holder.img_arrow.setBackgroundResource(R.mipmap.icon_detail_arrow);
        }
        holder.rlt_tittle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                batteryCaseOpen = !batteryCaseOpen;
                notifyDataSetChanged();
            }
        });
    }

    @Override
    public int getItemCount() {
        return 5;
    }


    private void setChart(LineChart mChart) {
        mChart.setHorizontalScrollBarEnabled(true);
        mChart.setExtraBottomOffset(10f);
        mChart.getDescription().setEnabled(false);
        // mChart.setDescription("");
        mChart.setDrawGridBackground(false);
        mChart.setHighlightPerDragEnabled(true);
        mChart.setScaleXEnabled(true);
        mChart.setScaleYEnabled(false);
        mChart.setDragEnabled(true);
        mChart.setTouchEnabled(true);
        mChart.setPinchZoom(true);
        //  mChart.setScaleEnabled(true);
        mChart.setDragDecelerationFrictionCoef(0.9f);
        mChart.setDoubleTapToZoomEnabled(false);
        MyMarkerView mv = new MyMarkerView(context, R.layout.custom_marker_view);
        // set the marker to the chart;
        mChart.setMarker(mv);
        mChart.zoom(3f, 1f, 0, 0);//显示的时候 是 按照多大的比率缩放显示   1f表示不放大缩小

        //   mChart.animateX(2500);
        // get the legend (only possible after setting data)
        Legend l = mChart.getLegend();
        l.setForm(Legend.LegendForm.CIRCLE);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);


        YAxis rightAxis = mChart.getAxisRight();
        rightAxis.setEnabled(false);


        XAxis xAxis = mChart.getXAxis();
        xAxis.setTextSize(11f);
        xAxis.enableGridDashedLine(10f, 10f, 0f);
        xAxis.setTextColor(Color.parseColor("#666666"));
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setYOffset(10f);
        xAxis.setAxisLineColor(Color.parseColor("#b9ccda"));
        xAxis.setGridColor(Color.parseColor("#b9ccda"));
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(true);
        xAxis.setDrawLabels(false);

        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setXOffset(15);
        leftAxis.setTextColor(Color.parseColor("#666666"));
        leftAxis.setAxisLineColor(Color.parseColor("#b9ccda"));
        leftAxis.setGridColor(Color.parseColor("#b9ccda"));
        leftAxis.setDrawGridLines(true);
        leftAxis.setGranularityEnabled(true);
        leftAxis.enableGridDashedLine(10f, 10f, 0f);
        leftAxis.setDrawZeroLine(false);
        leftAxis.setDrawLimitLinesBehindData(true);


    }


    /**
     * @param lineChart 总电压数据
     */
    private void setTotalVoltageData(LineChart lineChart) {
        ArrayList<Entry> yVals1 = new ArrayList<>();
        ArrayList<Entry> yVals2 = new ArrayList<>();
        //   List<String> indexList = new ArrayList<>();
        List<Float> value1 = new ArrayList<>();
        List<Float> value2 = new ArrayList<>();
        for (RxDiagnosisChart rxDiagnosisChart : list) {
            if (rxDiagnosisChart.getCode().equals("total_voltage")) {
                List<RxDiagnosisChart.ValuesBean> list1 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list1.size(); i++) {
                    value1.add(list1.get(i).getValue());
                    yVals1.add(new Entry(i, list1.get(i).getValue()));
//                    if (i == 0) {
//                        indexList.add(TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
//                    } else {
//                        indexList.add(TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
//                    }
                }
            }
            if (rxDiagnosisChart.getCode().equals("control_in_voltage")) {
                List<RxDiagnosisChart.ValuesBean> list2 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list2.size(); i++) {
                    value2.add(list2.get(i).getValue());
                    yVals2.add(new Entry(i, list2.get(i).getValue()));
//                    if (i == 0) {
//                        indexList.add(TimeUtils.stampTotime(list2.get(i).getCollectTime() + ""));
//                    } else {
//                        indexList.add(TimeUtils.stampTotime(list2.get(i).getCollectTime() + ""));
//                    }
                }
            }
        }

        LineDataSet set1, set2;
        set1 = new LineDataSet(yVals1, "总电压");
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);
        set1.setColor(Color.parseColor("#00b3f7"));
        set1.setCircleColor(Color.parseColor("#00b3f7"));
        set1.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set1.setFillAlpha(65);
        set1.setDrawCircleHole(true);
        set1.setHighlightEnabled(true);
        set1.setDrawValues(false);
        set1.setDrawIcons(false);

        set2 = new LineDataSet(yVals2, "电机控制器输入电压");
        set2.setDrawIcons(false);
        set2.setColor(Color.parseColor("#32e2a2"));
        set2.setCircleColor(Color.parseColor("#32e2a2"));
        set2.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set2.setFillAlpha(65);
        set2.setDrawCircleHole(true);
        set2.setHighlightEnabled(true);
        set2.setAxisDependency(YAxis.AxisDependency.LEFT);
        set2.setDrawValues(false);

//        ArrayList<ILineDataSet> dataSets = new ArrayList<>();
//        dataSets.add(set1);
//        dataSets.add(set2);

        LineData data = new LineData(set1, set2);
        data.setValueTextColor(Color.parseColor("#333333"));
        data.setValueTextSize(9f);

        lineChart.setData(data);
        // lineChart.setDragOffsetX(20f);
        //  lineChart.moveViewToX(-20);

//        YAxis leftAxis = lineChart.getAxisLeft();
//        float max = getMax(value1) > getMax(value2) ? getMax(value1) : getMax(value2);
//        float min = getMin(value1) < getMin(value2) ? getMin(value1) : getMin(value2);
//        setXMaxMinValue(max, min, leftAxis);

    }

    /**
     * @param lineChart 总电流数据
     */

    private void setTotalCurrentData(LineChart lineChart) {
        ArrayList<Entry> yVals1 = new ArrayList<Entry>();
        ArrayList<Entry> yVals2 = new ArrayList<Entry>();
//        List<String> indexList = new ArrayList<>();
//        List<Float> value1 = new ArrayList<>();
//        List<Float> value2 = new ArrayList<>();
        for (RxDiagnosisChart rxDiagnosisChart : list) {
            if (rxDiagnosisChart.getCode().equals("total_current")) {
                List<RxDiagnosisChart.ValuesBean> list1 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list1.size(); i++) {
                    //       value1.add(list1.get(i).getValue());
                    yVals1.add(new Entry(i, list1.get(i).getValue()));
                    if (i == 0) {
                        //         indexList.add("            " + TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
                    } else {
                        //          indexList.add(TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
                    }

                }
            }
            if (rxDiagnosisChart.getCode().equals("control_bus_current")) {
                List<RxDiagnosisChart.ValuesBean> list2 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list2.size(); i++) {
                    //   value2.add(list2.get(i).getValue());
                    yVals2.add(new Entry(i, list2.get(i).getValue()));
//                    if (i == 0) {
//                        indexList.add("            " + TimeUtils.stampTotime(list2.get(i).getCollectTime() + ""));
//                    } else {
//                        indexList.add(TimeUtils.stampTotime(list2.get(i).getCollectTime() + ""));
//                    }

                }
            }
        }

        LineDataSet set1, set2;
        set1 = new LineDataSet(yVals1, "总电流");
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);
        set1.setColor(Color.parseColor("#00b3f7"));
        set1.setCircleColor(Color.parseColor("#00b3f7"));
        set1.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set1.setFillAlpha(65);
        set1.setDrawCircleHole(true);
        set1.setHighlightEnabled(true);
        set1.setDrawValues(false);
        set1.setDrawIcons(false);

        set2 = new LineDataSet(yVals2, "电机控制器输入电压");
        set2.setColor(Color.parseColor("#32e2a2"));
        set2.setCircleColor(Color.parseColor("#32e2a2"));
        set2.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set2.setFillAlpha(65);
        set2.setDrawCircleHole(true);
        set2.setHighlightEnabled(true);
        set2.setDrawIcons(false);
        set2.setDrawValues(false);
        set2.setAxisDependency(YAxis.AxisDependency.LEFT);


        ArrayList<ILineDataSet> dataSets = new ArrayList<>();
        dataSets.add(set1);
        dataSets.add(set2);

        LineData data = new LineData(dataSets);
        data.setValueTextColor(Color.parseColor("#333333"));
        data.setValueTextSize(9f);

        lineChart.setData(data);
//        lineChart.setDragOffsetX(20f);
//        lineChart.moveViewToX(-20);
//        YAxis leftAxis = lineChart.getAxisLeft();
//        float max = getMax(value1) > getMax(value2) ? getMax(value1) : getMax(value2);
//        float min = getMin(value1) < getMin(value2) ? getMin(value1) : getMin(value2);
//        setXMaxMinValue(max, min, leftAxis);

    }

    /**
     * @param lineChart 单体电压数据
     */
    private void setMonomerVoltage(LineChart lineChart) {
        ArrayList<Entry> yVals1 = new ArrayList<Entry>();
        ArrayList<Entry> yVals2 = new ArrayList<Entry>();
//        List<String> indexList = new ArrayList<>();
        List<Float> value1 = new ArrayList<>();
        List<Float> value2 = new ArrayList<>();
        for (RxDiagnosisChart rxDiagnosisChart : list) {
            //单体最低电压
            if (rxDiagnosisChart.getCode().equals("battery_single_lowest_voltage")) {
                List<RxDiagnosisChart.ValuesBean> list1 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list1.size(); i++) {
                    yVals1.add(new Entry(i, list1.get(i).getValue()));
                    value1.add(list1.get(i).getValue());
//                    if (i == 0) {
//                        indexList.add("            " + TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
//                    } else {
//                        indexList.add(TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
//                    }

                }
            }
            //单体最高电压
            if (rxDiagnosisChart.getCode().equals("battery_single_highest_voltage")) {
                List<RxDiagnosisChart.ValuesBean> list2 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list2.size(); i++) {
                    yVals2.add(new Entry(i, list2.get(i).getValue()));
                    value2.add(list2.get(i).getValue());
                }
            }
        }


        LineDataSet set1, set2;
        set1 = new LineDataSet(yVals1, "最低电压");
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);
        set1.setColor(Color.parseColor("#32e2a2"));
        set1.setCircleColor(Color.parseColor("#32e2a2"));
        set1.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set1.setFillAlpha(65);
        set1.setDrawCircleHole(true);
        set1.setHighlightEnabled(true);
        set1.setDrawValues(false);
        set1.setDrawIcons(false);

        set2 = new LineDataSet(yVals2, "最高电压");
        set2.setColor(Color.parseColor("#00b3f7"));
        set2.setCircleColor(Color.parseColor("#00b3f7"));
        set2.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set2.setFillAlpha(65);
        set2.setDrawCircleHole(true);
        set2.setHighlightEnabled(true);
        set2.setDrawValues(false);
        set2.setDrawIcons(false);
        set2.setAxisDependency(YAxis.AxisDependency.LEFT);


        ArrayList<ILineDataSet> dataSets = new ArrayList<>();

        dataSets.add(set1);
        dataSets.add(set2);

        LineData data = new LineData(dataSets);
        data.setValueTextColor(Color.parseColor("#333333"));
        data.setValueTextSize(9f);
        lineChart.setData(data);
//        lineChart.setDragOffsetX(20f);
//        lineChart.moveViewToX(-20);
//
        YAxis leftAxis = lineChart.getAxisLeft();
        float max = getMax(value1) > getMax(value2) ? getMax(value1) : getMax(value2);
        float min = getMin(value1) < getMin(value2) ? getMin(value1) : getMin(value2);
        setXMaxMinValue(max, min, leftAxis);

    }

    /**
     * @param lineChart 绝缘电阻数据
     */

    private void setResistanceData(LineChart lineChart) {
        ArrayList<Entry> yVals1 = new ArrayList<Entry>();
//        List<String> indexList = new ArrayList<>();
//        List<Float> value1 = new ArrayList<>();
        for (RxDiagnosisChart rxDiagnosisChart : list) {
            if (rxDiagnosisChart.getCode().equals("insulation_resistance")) {
                List<RxDiagnosisChart.ValuesBean> list1 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list1.size(); i++) {
                    //    value1.add(list1.get(i).getValue());
                    yVals1.add(new Entry(i, list1.get(i).getValue()));
//                    if (i == 0) {
//                        indexList.add(TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
//                    } else {
//                        indexList.add(TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
//                    }

                }
            }
        }

        LineDataSet set1;
        set1 = new LineDataSet(yVals1, "绝缘电阻");
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);
        set1.setColor(Color.parseColor("#00b3f7"));
        set1.setCircleColor(Color.parseColor("#00b3f7"));
        set1.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set1.setFillAlpha(65);
        set1.setDrawCircleHole(true);
        set1.setHighlightEnabled(true);
        set1.setDrawValues(false);
        set1.setDrawIcons(false);
        ArrayList<ILineDataSet> dataSets = new ArrayList<>();
        dataSets.add(set1);


        LineData data = new LineData(dataSets);
        data.setValueTextColor(Color.parseColor("#333333"));
        data.setValueTextSize(9f);

        lineChart.setData(data);
//        lineChart.setDragOffsetX(20f);
//        lineChart.moveViewToX(-20);
//
//        YAxis leftAxis = lineChart.getAxisLeft();
//        float max = getMax(value1);
//        float min = getMin(value1);
//        setXMaxMinValue(max, min, leftAxis);
    }

    /**
     * @param lineChart 探针温度数据
     */
    private void setBatteryCaseVoltage(LineChart lineChart) {
        ArrayList<Entry> yVals1 = new ArrayList<Entry>();
        ArrayList<Entry> yVals2 = new ArrayList<Entry>();
//        List<Float> value1 = new ArrayList<>();
//        List<Float> value2 = new ArrayList<>();
//        List<String> indexList = new ArrayList<>();
        for (RxDiagnosisChart rxDiagnosisChart : list) {
            //最低温度
            if (rxDiagnosisChart.getCode().equals("lowest_temp")) {
                List<RxDiagnosisChart.ValuesBean> list1 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list1.size(); i++) {
                    //    value1.add(list1.get(i).getValue());
                    yVals1.add(new Entry(i, list1.get(i).getValue()));
//                    if (i == 0) {
//                        indexList.add("            " + TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
//                    } else {
//                        indexList.add(TimeUtils.stampTotime(list1.get(i).getCollectTime() + ""));
//                    }

                }
            }
            //最高温度
            if (rxDiagnosisChart.getCode().equals("highest_temp")) {
                List<RxDiagnosisChart.ValuesBean> list1 = rxDiagnosisChart.getValues();
                for (int i = 0; i < list1.size(); i++) {
                    // value2.add(list1.get(i).getValue());
                    yVals2.add(new Entry(i, list1.get(i).getValue()));
                }
            }
        }


        LineDataSet set1, set2;
        set1 = new LineDataSet(yVals1, "最低温度");

        set1.setAxisDependency(YAxis.AxisDependency.LEFT);
        set1.setColor(Color.parseColor("#32e2a2"));
        set1.setCircleColor(Color.parseColor("#32e2a2"));
        set1.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set1.setFillAlpha(65);
        set1.setDrawCircleHole(true);
        set1.setHighlightEnabled(true);
        set1.setDrawValues(false);
        set1.setDrawIcons(false);

        set2 = new LineDataSet(yVals2, "最高温度");

        set2.setAxisDependency(YAxis.AxisDependency.LEFT);
        set2.setColor(Color.parseColor("#00b3f7"));
        set2.setCircleColor(Color.parseColor("#00b3f7"));
        set2.setLineWidth(2f);
        set1.setCircleRadius(CircleRadius);
        set1.setCircleHoleRadius(CircleHoleRadius);
        set2.setFillAlpha(65);
        set2.setDrawCircleHole(true);
        set2.setHighlightEnabled(true);
        set2.setDrawValues(false);
        set2.setDrawIcons(false);

        ArrayList<ILineDataSet> dataSets = new ArrayList<>();

        dataSets.add(set1);
        dataSets.add(set2);

        LineData data = new LineData(dataSets);
        data.setValueTextColor(Color.parseColor("#333333"));
        data.setValueTextSize(9f);

        lineChart.setData(data);
//        lineChart.setDragOffsetX(20f);
//        lineChart.moveViewToX(-20);
//
//        YAxis leftAxis = lineChart.getAxisLeft();
//        float max = getMax(value1) > getMax(value2) ? getMax(value1) : getMax(value2);
//        float min = getMin(value1) < getMin(value2) ? getMin(value1) : getMin(value2);
//        setXMaxMinValue(max, min, leftAxis);

    }


    private void setXMaxMinValue(float max, float min, YAxis leftAxis) {
        leftAxis.setAxisMinimum(min-1);
        leftAxis.setAxisMaximum(max+1);
    }


    /**
     * @param list
     * @return 返回数组中最大值
     */
    private float getMax(List<Float> list) {

        float max = 0;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) > max) {
                max = list.get(i);
            }
        }
        return max;
    }

    /**
     * @param list
     * @return 返回数组中最小值
     */
    private float getMin(List<Float> list) {
        float min = 0;
        if (list.size() > 0) {
            min = list.get(0);
        }
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) < min) {
                min = list.get(i);
            }
        }
        return min;
    }


    /**
     * 总电压
     */
    class VoltageHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.chart)
        LineChart lineChart;
        @BindView(R.id.rlt_tittle)
        RelativeLayout rlt_tittle;
        @BindView(R.id.img_arrow)
        ImageView img_arrow;

        VoltageHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    /**
     * 总电流
     */
    class ElectricHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.chart)
        LineChart lineChart;
        @BindView(R.id.rlt_tittle)
        RelativeLayout rlt_tittle;
        @BindView(R.id.img_arrow)
        ImageView img_arrow;

        ElectricHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    /**
     * 单体电压
     */
    class MonomerVoltageHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.chart)
        LineChart lineChart;
        @BindView(R.id.rlt_tittle)
        RelativeLayout rlt_tittle;
        @BindView(R.id.img_arrow)
        ImageView img_arrow;

        MonomerVoltageHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    /**
     * 绝缘电阻
     */
    class ResistanceHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.chart)
        LineChart lineChart;
        @BindView(R.id.rlt_tittle)
        RelativeLayout rlt_tittle;
        @BindView(R.id.img_arrow)
        ImageView img_arrow;

        ResistanceHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    /**
     * 电池箱
     */
    class BatteryCaseHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.chart)
        LineChart lineChart;
        @BindView(R.id.rlt_tittle)
        RelativeLayout rlt_tittle;
        @BindView(R.id.img_arrow)
        ImageView img_arrow;

        BatteryCaseHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
